﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Sector7.Framework.Core;
using Sector7.Medical.Biz;
using Sector7.Medical.Enums;
using Sector7.Framework.Utility;
using Sector7.Medical.Consts;
using Sector7.Framework.Enums;

namespace Sector7.Medical.SYSM.Controls
{
    /// <summary>
    /// LoginControl.xaml 的交互逻辑
    /// </summary>
    public partial class LoginControl : LoginControlBase
    {
        #region ============================================== Accessor
        #endregion

        #region ============================================== Public functions
        #endregion

        #region ============================================== Private Functions
        #endregion

        #region ============================================== Event Functions
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            string username = txbUsername.Text;
            string password = txbPassword.Password;
            password = EncryptionUtil.MD5Encrypt(password, C_DecrKey.KEY_USER_PASSWORD);

            string uniqueId = Agent_SYSS.Login(username, password, AccessRoleType.Employee);
            if (uniqueId.Contains("#"))
            {
                string[] msgs = uniqueId.Split('#');
                Alert.ShowDialog(AlertType.Error, string.Format("{0}: {1}", msgs[0], msgs[1]));
            }
            else
            {
                var employee = Agent_SYSS.GetEmployee(uniqueId);

                if (employee != null)
                {
                    Senvironments.CurrentAccount = employee;
                    OnLoginSuccess(new EventArgs());
                }
                else
                {
                    Alert.ShowDialog(AlertType.Error, "无法找到用户！");
                }
            }
        }

        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            OnClickClose(new EventArgs());
        }
        #endregion

        #region ============================================== Structure
        public LoginControl()
        {
            InitializeComponent();
        }
        #endregion

        #region ============================================== Inner members
        #endregion
    }
}
